package breadth_first_search;

/**
 * author :  apurv verma
 * email  :  dapurv5@gmail.com
 */

import java.io.*;
import java.util.Scanner;


public class Maze2D {
	
	int n;
	protected int maze[][];
	protected int OBSTACLE_CELL=-1;
	protected int VALID_CELL=0;
	protected int START_CELL=-2;
	protected int GOAL_CELL=-3;	
	protected Dimension startLoc;
	protected Dimension goalLoc;
	
	public Maze2D(int size, Dimension startLoc, Dimension goalLoc, String filename){
		n=size;
		this.startLoc=startLoc;
		this.goalLoc=goalLoc;
		maze=new int[n][n];
		maze[startLoc.getX()][startLoc.getY()]=START_CELL;
		maze[goalLoc.getX()][goalLoc.getY()]=GOAL_CELL;
		initMaze(filename);
	}
	
	/*
	 * The function reads from the file named "filename.txt". The format of the file can be seen from the sample file.
	 */
	public void initMaze(String filename){
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				maze[i][j]=VALID_CELL;
			}
		}
		
		try{
		Scanner scanner=new Scanner(new BufferedReader(new FileReader(filename)));
		while(scanner.hasNext()){
			int x=scanner.nextInt();
			int y=scanner.nextInt();
			
			assert(x!=startLoc.getX() && y!=startLoc.getY());
			assert(x!=goalLoc.getX() && y!=goalLoc.getY());
			
			maze[x][y]=OBSTACLE_CELL;
		}
		}
		catch(Exception e){e.printStackTrace();}
	}
}
